package com.nanyang.tms.controller.company;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.common.core.page.PageBean;
import com.nanyang.tms.api.dto.request.companypickaddress.*;
import com.nanyang.tms.api.dto.response.companypickaddress.CompanyPickAddressPageResponse;
import com.nanyang.tms.api.dto.response.companypickaddress.CompanyPickAddressResponse;
import com.nanyang.tms.api.service.companypickaddress.CompanyPickAddressRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/companypickaddress")
public class CompanyPickAddressController {

    @Reference(version = "1.0.0", timeout = 10000, check = false)
    private CompanyPickAddressRpcService companyPickAddressRpcService;

    /**
     * <p>listCompanyPickAddress</p>
     * <p>Description:查询列表</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @BindParam
    public ApiResult<PageBean<CompanyPickAddressPageResponse>> listCompanyPickAddress(@BindParam @RequestBody CompanyPickAddressQueryRequest param) {
        ApiResult<PageBean<CompanyPickAddressPageResponse>> apiResult = companyPickAddressRpcService.listCompanyPickAddress(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * <p>listCompanyPickAddress</p>
     * <p>Description:查询根据编码</p>
     *
     * @param param
     * @return
     */
    @RequestMapping(value = "/selectByCode", method = RequestMethod.POST)
    @BindParam
    public ApiResult<CompanyPickAddressResponse> selectByCode(@BindParam @RequestBody CompanyPickAddressQueryRequest param) {
        ApiResult<CompanyPickAddressResponse> apiResult = companyPickAddressRpcService.selectByCode(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 添加-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> saveProduct(@BindParam @RequestBody @Valid CompanyPickAddressAddRequest param) {
        ApiResult<Boolean> apiResult = companyPickAddressRpcService.saveCompanyPickAddress(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 修改-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> updateCompanyPickAddress(@BindParam @RequestBody @Valid CompanyPickAddressUpdateRequest param) {
        ApiResult<Boolean> apiResult = companyPickAddressRpcService.updateCompanyPickAddress(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }

    /**
     * 设置默认-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/updateDefault", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> updateDefault(@BindParam @RequestBody @Valid CompanyPickAddressDefautRequest param) {
        ApiResult<Boolean> apiResult = companyPickAddressRpcService.updateDefault(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
    /**
     * 删除-前台
     * @param param
     * @return
     */

    @RequestMapping(value = "/del", method = RequestMethod.POST)
    @BindParam
    public ApiResult<Boolean> delCompanyPickAddress(@BindParam @RequestBody @Valid CompanyPickAddressDelRequest param) {
        ApiResult<Boolean> apiResult = companyPickAddressRpcService.delCompanyPickAddress(param);
        if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
        }
        return apiResult;
    }
}
